function checkLocation(seq) {
	
	str     = eval('document.assemblyForm.select_'+seq+'.checked');	
	var cnt = document.assemblyForm.count.value;
	var maxVal = 0;
	if(cnt!=1)
	{	
		var rawCheck = eval('document.assemblyForm.rawMaterialSource_'+seq);
		var str_raw = eval('document.assemblyForm.rawMaterialSource_'+seq+'.checked');
		if(str==false)
		{
			document.assemblyForm.priority[seq].disabled=true;
			document.assemblyForm.split[seq].disabled=true;
			document.assemblyForm.capacityWeek[seq].disabled=true;
			document.assemblyForm.normalCost[seq].disabled=true;
			document.assemblyForm.expressCost[seq].disabled=true;
			document.assemblyForm.locationName[seq].disabled=true;
			document.assemblyForm.normalCycleTime[seq].disabled=true;
			document.assemblyForm.expressCycleTime[seq].disabled=true;
			document.assemblyForm.expectedYield[seq].disabled=true;
			rawCheck.disabled=true;
			document.assemblyForm.rawLevelMin[seq].disabled=true;
			document.assemblyForm.rawLevelMax[seq].disabled=true;
			// added to set the default priority by ravikanth
			maxVal =  document.assemblyForm.priority[seq].value;
			for ( var y =0 ; y < cnt ; y++ )
			{
				temp   = document.assemblyForm.priority[y].value;
				if( temp > maxVal && maxVal != 0)
				{
					document.assemblyForm.priority[y].value = parseInt(document.assemblyForm.priority[y].value) -1;
				}
			}

			document.assemblyForm.priority[seq].value='';

		}

		if(str==true)
		{
			document.assemblyForm.priority[seq].disabled=false;
            document.assemblyForm.split[seq].disabled=false;
            document.assemblyForm.capacityWeek[seq].disabled=false;
            document.assemblyForm.normalCost[seq].disabled=false;
            document.assemblyForm.expressCost[seq].disabled=false;
            //document.assemblyForm.locationName[seq].disabled=false;
            document.assemblyForm.normalCycleTime[seq].disabled=false;
            document.assemblyForm.expressCycleTime[seq].disabled=false;
            document.assemblyForm.expectedYield[seq].disabled=false;
            rawCheck.disabled=false;
            if(str_raw == true)
			{
				document.assemblyForm.rawLevelMin[seq].disabled=false;
                document.assemblyForm.rawLevelMax[seq].disabled=false;
            }
			// added to set the default priority by ravikanth
			for ( var y =0 ; y < cnt ; y++ )
			{
				temp   = document.assemblyForm.priority[y].value;
				if( temp > maxVal)
				{
					maxVal = temp
				}
			}		
			document.assemblyForm.priority[seq].value= parseInt(maxVal)+1 ;
		}
	}
	else
	{
		if(str==false)
		{
			document.assemblyForm.priority.disabled=true;
			document.assemblyForm.split.disabled=true;
			document.assemblyForm.capacityWeek.disabled=true;
			document.assemblyForm.normalCost.disabled=true;
			document.assemblyForm.expressCost.disabled=true;
			document.assemblyForm.locationName.disabled=true;
			document.assemblyForm.normalCycleTime.disabled=true;
			document.assemblyForm.expressCycleTime.disabled=true;
			document.assemblyForm.expectedYield.disabled=true;
			document.assemblyForm.rawMaterialSource_0.disabled=true;
			document.assemblyForm.rawLevelMin.disabled=true;
			document.assemblyForm.rawLevelMax.disabled=true;
			document.assemblyForm.priority.value='';
		}

		if(str==true)
		{
			document.assemblyForm.priority.disabled=false;
			document.assemblyForm.split.disabled=false;
			document.assemblyForm.capacityWeek.disabled=false;
			document.assemblyForm.normalCost.disabled=false;
			document.assemblyForm.expressCost.disabled=false;
			//document.assemblyForm.locationName.disabled=false;
			document.assemblyForm.normalCycleTime.disabled=false;
			document.assemblyForm.expressCycleTime.disabled=false;
			document.assemblyForm.expectedYield.disabled=false;
			document.assemblyForm.rawMaterialSource_0.disabled=false;
			if(str_raw == true){
				document.assemblyForm.rawLevelMin.disabled=false;
				document.assemblyForm.rawLevelMax.disabled=false;
			}
			document.assemblyForm.priority.value=1;

		}
	}
}



function checkRaw(seq) {
	
			str     = eval('document.assemblyForm.rawMaterialSource_'+seq+'.checked');	
			var cnt = document.assemblyForm.count.value;
							
			 if(cnt!=1)
			{								
				if(str==false){
				document.assemblyForm.rawLevelMin[seq].disabled=true;
				document.assemblyForm.rawLevelMax[seq].disabled=true;
				}

				if(str==true){
				document.assemblyForm.rawLevelMin[seq].disabled=false;
				document.assemblyForm.rawLevelMax[seq].disabled=false;
				}
		
			}
			
		   else{

			if(str==false){
				document.assemblyForm.rawLevelMin.disabled=true;
				document.assemblyForm.rawLevelMax.disabled=true;
				
				}

				if(str==true){
				document.assemblyForm.rawLevelMin.disabled=false;
				document.assemblyForm.rawLevelMax.disabled=false;
				
				}


		   }
}



function whileLoad()
{

	var cnt = document.assemblyForm.count.value;

	if(cnt==1)
	{ 
		str     = eval('document.assemblyForm.select_0.checked');
		str_raw = eval('document.assemblyForm.rawMaterialSource_0.checked');
		var rawCheck = eval('document.assemblyForm.rawMaterialSource_'+'0');
		if(str==false){

				document.assemblyForm.priority.disabled=true;
				document.assemblyForm.split.disabled=true;
				document.assemblyForm.capacityWeek.disabled=true;
				document.assemblyForm.normalCost.disabled=true;
				document.assemblyForm.expressCost.disabled=true;
				document.assemblyForm.locationName.disabled=true;
				document.assemblyForm.normalCycleTime.disabled=true;
				document.assemblyForm.expressCycleTime.disabled=true;
				document.assemblyForm.expectedYield.disabled=true;
				if(str_raw==false){		
				document.assemblyForm.rawLevelMin.disabled=true;
				document.assemblyForm.rawLevelMax.disabled=true;
				}
				}

				if(str==true){
				document.assemblyForm.priority.disabled=false;
				document.assemblyForm.split.disabled=false;
				document.assemblyForm.capacityWeek.disabled=false;
				document.assemblyForm.normalCost.disabled=false;
				document.assemblyForm.expressCost.disabled=false;
				//document.assemblyForm.locationName.disabled=false;
				document.assemblyForm.normalCycleTime.disabled=false;
				document.assemblyForm.expressCycleTime.disabled=false;
				document.assemblyForm.expectedYield.disabled=false;
				rawCheck.disabled=false;
				if(str_raw==true){
				document.assemblyForm.rawLevelMin.disabled=false;
				document.assemblyForm.rawLevelMax.disabled=false;
				}
				else{
				document.assemblyForm.rawLevelMin.disabled=true;
				document.assemblyForm.rawLevelMax.disabled=true;
				}

				//document.assemblyForm.rawLevelMin.disabled=false;
				//document.assemblyForm.rawLevelMax.disabled=false;
						
				}

	}


	else{

	for(var i=0;i<cnt;i++){
			
				str     = eval('document.assemblyForm.select_'+i+'.checked');
				str_raw = eval('document.assemblyForm.rawMaterialSource_'+i+'.checked');
				var rawCheck = eval('document.assemblyForm.rawMaterialSource_'+i);
				
				if(str==false){
				document.assemblyForm.priority[i].disabled=true;
				document.assemblyForm.split[i].disabled=true;
				document.assemblyForm.capacityWeek[i].disabled=true;
				document.assemblyForm.normalCost[i].disabled=true;
				document.assemblyForm.expressCost[i].disabled=true;
				document.assemblyForm.locationName[i].disabled=true;
				document.assemblyForm.normalCycleTime[i].disabled=true;
				document.assemblyForm.expressCycleTime[i].disabled=true;
				document.assemblyForm.expectedYield[i].disabled=true;
				rawCheck.disabled=true;
				document.assemblyForm.rawLevelMin[i].disabled=true;
				document.assemblyForm.rawLevelMax[i].disabled=true;
			
				}

				else if(str==true){
				document.assemblyForm.priority[i].disabled=false;
				document.assemblyForm.split[i].disabled=false;
				document.assemblyForm.capacityWeek[i].disabled=false;
				document.assemblyForm.normalCost[i].disabled=false;
				document.assemblyForm.expressCost[i].disabled=false;
				//document.assemblyForm.locationName[i].disabled=false;
				document.assemblyForm.normalCycleTime[i].disabled=false;
				document.assemblyForm.expressCycleTime[i].disabled=false;
				document.assemblyForm.expectedYield[i].disabled=false;
				rawCheck.disabled=false;
				if(str_raw==true){
				document.assemblyForm.rawLevelMin[i].disabled=false;
				document.assemblyForm.rawLevelMax[i].disabled=false;
				}
				else{
				document.assemblyForm.rawLevelMin[i].disabled=true;
				document.assemblyForm.rawLevelMax[i].disabled=true;
				}
				}

				
	}

	}
	
		
}




function saveAssemblyData()
{
	
	var cnt						= document.assemblyForm.count.value;
	var pa						= document.getElementById("message");
	var std_unit_cost			= document.assemblyForm.standardUnitCost.value;
	var lot_scrap_yield_limit   = document.assemblyForm.lotScrapYieldLimit.value;
	var target_yield			= document.assemblyForm.targetYield.value;
	
	var vendorCnt				= 0;
	var vendorPriority			=  null;
	// added by ravikanth on 30-Sep-2003

	if(trim(document.assemblyForm.productName.value)=='')
	{
		pa.innerHTML = "Assembly Product Name cannot be null or contain spaces ";	
		document.assemblyForm.productName.value = '';
		document.assemblyForm.productName.focus();
		return;
	}
	else
	{
		document.assemblyForm.productName.value = document.assemblyForm.productName.value.trim();
	}

	if( typeof document.assemblyForm.locationName.length == 'undefined' )
	{
		if ( document.assemblyForm.select_0.checked+"" == "true" )
		{
			vendorCnt++;
		}
		
		if(  vendorCnt > 0 && (document.assemblyForm.priority.value =='0' || document.assemblyForm.priority.value.trim().length == 0 ) )
		{
			pa.innerHTML = "Priority cannot 0 or empty ";	
			document.assemblyForm.priority.value='';
			document.assemblyForm.priority.focus();
			return; 
		}
	}
	else
	{
		vendorPriority = new Array(document.assemblyForm.locationName.length);

		for (var x=0 ; x < document.assemblyForm.locationName.length ; x++ )
		{
			var temp = eval("document.assemblyForm.select_"+x);

			if( temp.checked+"" == "true" )
			{
				vendorCnt++;
				if (document.assemblyForm.priority[x].value == 0 || document.assemblyForm.priority[x].value.trim().length == 0 )
				{
					
					pa.innerHTML = "Vendor priority cannot 0 or empty ";	
					document.assemblyForm.priority[x].value = '';
					document.assemblyForm.priority[x].focus();
					return; 
				}
				vendorPriority[x] = document.assemblyForm.priority[x].value
			}
		}
	}

	if( vendorCnt == 0)
	{
		pa.innerHTML = "Should select atleast one vendor";	
		return; 
	}

	if( vendorCnt > 1 )
	{
		
		for ( y=0 ; y < vendorPriority.length -1 ; y++ )
		{
			for ( z = y+1 ; z < vendorPriority.length ; z++ )
			{
				if( vendorPriority[y] != null && vendorPriority[z] != null && vendorPriority[y] != 0 && vendorPriority[z] !=0 )
				{
					if ( vendorPriority[z] == vendorPriority[y])
					{
						pa.innerHTML = "Two vendor priorities cannot be same ";	
						return; 
					}
				}
			}
		}
	}

	var flag = checkDupInProduct(document.assemblyForm.productName,document.assemblyForm.dupProductName);
	if( flag != -1 )
	{
		if( typeof document.assemblyForm.dupProductName.length == 'undefined' )
		{
			document.assemblyForm.dupProductName.focus();
		}
		else
		{
			document.assemblyForm.dupProductName[flag].focus();	
		}
		pa.innerHTML = "Two Part numbers cannot be same";	
		return; 
	}

	if(std_unit_cost!=''){
		if(!isFloat(std_unit_cost)){	
 	    pa.innerHTML = "Please enter valid Standard Unit Cost,It must be float";
		document.assemblyForm.standardUnitCost.select();
		document.assemblyForm.standardUnitCost.focus();
		return;
		}	
	}

	if(lot_scrap_yield_limit!=''){
		if(!isFloat(lot_scrap_yield_limit)){	
 	    pa.innerHTML = "Please enter valid Lot Scrap Yield Limit,It must be float";
		document.assemblyForm.lotScrapYieldLimit.select();
		document.assemblyForm.lotScrapYieldLimit.focus();
		return;
		}	
	}

	if(target_yield!=''){
		if(!isFloat(target_yield)){	
 	    pa.innerHTML = "Please enter valid Target Yield,It must be Float";
		document.assemblyForm.targetYield.select();
		document.assemblyForm.targetYield.focus();
		return;
		}	
	}



	if(cnt==1)
	{ 
		str     = eval('document.assemblyForm.select_0.checked');
		
				if(str==true){
                var priority		= document.assemblyForm.priority.value;
				var split			= document.assemblyForm.split.value;
				var capacity_week   = document.assemblyForm.capacityWeek.value;
				var normal_cost		= document.assemblyForm.normalCost.value;
				var express_cost	= document.assemblyForm.expressCost.value;
				var normal_time		= document.assemblyForm.normalCycleTime.value;
				var express_time	= document.assemblyForm.expressCycleTime.value;
				var yield			= document.assemblyForm.expectedYield.value;
		
				str_raw     = eval('document.assemblyForm.rawMaterialSource_0.checked');

				if(priority!=''){
				if (!isInteger(priority)){
				pa.innerHTML = "Please enter valid Priority,It must be number";
				document.assemblyForm.priority.select();
				document.assemblyForm.priority.focus();
				return;
				}
				}

				if(split!=''){
				if (!isFloat(split)){
				pa.innerHTML = "Please enter valid Split,It must be float";
				document.assemblyForm.split.select();
				document.assemblyForm.split.focus();
				return;
				}
				}

				if(capacity_week!=''){
				if (!isInteger(capacity_week)){
				pa.innerHTML = "Please enter valid Capacity Per Week,It must be number";
				document.assemblyForm.capacityWeek.select();
				document.assemblyForm.capacityWeek.focus();
				return;
				}
				}

				if(normal_cost!=''){
				if (!isFloat(normal_cost)){
				pa.innerHTML = "Please enter valid Normal Cost,It must be float";
				document.assemblyForm.normalCost.select();
				document.assemblyForm.normalCost.focus();
				return;
				}
				}

				if(express_cost!=''){
				if (!isFloat(express_cost)){
				pa.innerHTML = "Please enter valid Express Cost,It must be float";
				document.assemblyForm.expressCost.select();
				document.assemblyForm.expressCost.focus();
				return;
				}
				}

				if(normal_time!=''){
				if (!isInteger(normal_time)){
				pa.innerHTML = "Please enter valid Normal Time,It must be number";
				document.assemblyForm.normalCycleTime.select();
				document.assemblyForm.normalCycleTime.focus();
				return;
				}
				}

				if(express_time!=''){
				if (!isInteger(express_time)){
				pa.innerHTML = "Please enter valid Express Time,It must be number";
				document.assemblyForm.expressCycleTime.select();
				document.assemblyForm.expressCycleTime.focus();
				return;
				}
				}

				if(yield!=''){
				if (!isFloat(yield)){
				pa.innerHTML = "Please enter valid Expected yield,It must be float";
				document.assemblyForm.expectedYield.select();
				document.assemblyForm.expectedYield.focus();
				return;
				}
				}

				if(str_raw==true){
				min_Level=document.assemblyForm.rawLevelMin.value;
				max_Level=document.assemblyForm.rawLevelMax.value;

				if(min_Level!=''){
				if (!isInteger(min_Level)){
				pa.innerHTML = "Please enter valid Raw Material Min Level,It must be number";
				document.assemblyForm.rawLevelMin.select();
				document.assemblyForm.rawLevelMin.focus();
				return;
				}
				}

				if(max_Level!=''){
				if (!isInteger(max_Level)){
				pa.innerHTML = "Please enter valid Raw Material Max Level,It must be number";
				document.assemblyForm.rawLevelMax.select();
				document.assemblyForm.rawLevelMax.focus();
				return;
				}
				}

				}
				
			}

	}


	else{
		
	for(var i=0;i<cnt;i++){
			
				str     = eval('document.assemblyForm.select_'+i+'.checked');
				
				if(str==true){
				var priority		= document.assemblyForm.priority[i].value;
				var split			= document.assemblyForm.split[i].value;
				var capacity_week   = document.assemblyForm.capacityWeek[i].value;
				var normal_cost		= document.assemblyForm.normalCost[i].value;
				var express_cost	= document.assemblyForm.expressCost[i].value;
				var normal_time		= document.assemblyForm.normalCycleTime[i].value;
				var express_time	= document.assemblyForm.expressCycleTime[i].value;
				var yield			= document.assemblyForm.expectedYield[i].value;
				str_raw				= eval('document.assemblyForm.rawMaterialSource_'+i+'.checked');
		
				if(priority!=''){
				if (!isInteger(priority)){
				pa.innerHTML = "Please enter valid Priority,It must be number";
				document.assemblyForm.priority[i].select();
				document.assemblyForm.priority[i].focus();
				return;
				}
				}

				if(split!=''){
				if (!isFloat(split)){
				pa.innerHTML = "Please enter valid Split,It must be float";
				document.assemblyForm.split[i].select();
				document.assemblyForm.split[i].focus();
				return;
				}
				}

				if(capacity_week!=''){
				if (!isInteger(capacity_week)){
				pa.innerHTML = "Please enter valid Capacity Per Week,It must be number";
				document.assemblyForm.capacityWeek[i].select();
				document.assemblyForm.capacityWeek[i].focus();
				return;
				}
				}

				if(normal_cost!=''){
				if (!isFloat(normal_cost)){
				pa.innerHTML = "Please enter valid Normal Cost,It must be float";
				document.assemblyForm.normalCost[i].select();
				document.assemblyForm.normalCost[i].focus();
				return;
				}
				}

				if(express_cost!=''){
				if (!isFloat(express_cost)){
				pa.innerHTML = "Please enter valid Express Cost,It must be float";
				document.assemblyForm.expressCost[i].select();
				document.assemblyForm.expressCost[i].focus();
				return;
				}
				}

				if(normal_time!=''){
				if (!isInteger(normal_time)){
				pa.innerHTML = "Please enter valid Normal Time,It must be number";
				document.assemblyForm.normalCycleTime[i].select();
				document.assemblyForm.normalCycleTime[i].focus();
				return;
				}
				}

				if(express_time!=''){
				if (!isInteger(express_time)){
				pa.innerHTML = "Please enter valid Express Time,It must be number";
				document.assemblyForm.expressCycleTime[i].select();
				document.assemblyForm.expressCycleTime[i].focus();
				return;
				}
				}

				if(yield!=''){
				if (!isFloat(yield)){
				pa.innerHTML = "Please enter valid Expected yield,It must be float";
				document.assemblyForm.expectedYield[i].select();
				document.assemblyForm.expectedYield[i].focus();
				return;
				}
				}

				if(str_raw==true){
				min_Level=document.assemblyForm.rawLevelMin[i].value;
				max_Level=document.assemblyForm.rawLevelMax[i].value;

				if(min_Level!=''){
				if (!isInteger(min_Level)){
				pa.innerHTML = "Please enter valid Raw Material Min Level,It must be number";
				document.assemblyForm.rawLevelMin[i].select();
				document.assemblyForm.rawLevelMin[i].focus();
				return;
				}
				}

				if(max_Level!=''){
				if (!isInteger(max_Level)){
				pa.innerHTML = "Please enter valid Raw Material Max Level,It must be number";
				document.assemblyForm.rawLevelMax[i].select();
				document.assemblyForm.rawLevelMax[i].focus();
				return;
				}
				}

				}


				}
				
	}

	}
	

	if(cnt!=1){
	for(var i=0;i<cnt;i++){

				str = eval('document.assemblyForm.select_'+i);
				str_raw = eval('document.assemblyForm.rawMaterialSource_'+i);
				document.assemblyForm.priority[i].disabled=false;
				document.assemblyForm.split[i].disabled=false;
				document.assemblyForm.capacityWeek[i].disabled=false;
				document.assemblyForm.normalCost[i].disabled=false;
				document.assemblyForm.expressCost[i].disabled=false;
				document.assemblyForm.locationName[i].disabled=false;
				document.assemblyForm.normalCycleTime[i].disabled=false;
				document.assemblyForm.expressCycleTime[i].disabled=false;
				document.assemblyForm.expectedYield[i].disabled=false;
				document.assemblyForm.rawLevelMin[i].disabled=false;
				document.assemblyForm.rawLevelMax[i].disabled=false;
				document.assemblyForm.locationName[i].disabled=false;
				str.disabled = false;
				str_raw.disabled = false;

	}
	}

	else{

		str = eval('document.assemblyForm.select_0');
		str_raw = eval('document.assemblyForm.rawMaterialSource_0');
		document.assemblyForm.priority.disabled=false;
		document.assemblyForm.split.disabled=false;
		document.assemblyForm.capacityWeek.disabled=false;
		document.assemblyForm.normalCost.disabled=false;
		document.assemblyForm.expressCost.disabled=false;
		document.assemblyForm.locationName.disabled=false;
		document.assemblyForm.normalCycleTime.disabled=false;
		document.assemblyForm.expressCycleTime.disabled=false;
		document.assemblyForm.expectedYield.disabled=false;
		document.assemblyForm.locationName.disabled=false;
		str.disabled		= false;
		str_raw.disabled	= false;
		document.assemblyForm.rawLevelMin.disabled=false;
		document.assemblyForm.rawLevelMax.disabled=false;
		
	    }
		document.assemblyForm.submit();
		
}